#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#

#define NUM 16

const char*myfile = "/home/fpq/linux-learning/code/shell";

int main(int argc,char* argv[],char* env[])
{

  char *const _env[NUM] = {
    (char*)"MY_105_VAL=20240527",
    NULL
  };

  pid_t id = fork();
  if(id == 0)
  {
    //子进程
    //ls -a -l
    printf("子进程开始进行，pid：%d\n",getpid());

    // 显示一个提示行 root@localhost#
    printf("root@localhost#\n");
    sleep(3);
    char *const _argv[NUM]={
       (char*) "ls",
       (char*)"-a",
       (char*)"-l",
       NULL
    };
 
    execl(myfile,"mycmd","-b",NULL);
    //execv("/usr/bin/ls",_argv);
    //execvp("ls",_argv);
    //execlp("ls","ls","-a","-l",NULL);
    //execl("/usr/bin/ls","-a","-l",NULL);
    exit(1);
   }

  else 
  {
    //父进程
    printf("父进程开始运行：pid：%d\n",getpid());
    int status = 0;
    pid_t id = waitpid(-1,&status,0);   //阻塞等待，一定是子进程先运行完毕，然后父进程获取之后，才退出。
    if(id > 0)
    {
      printf("wait success,exit code：%d\n",WEXITSTATUS(status));
    }
  }
	  
  return 0;
}


